#include "ClassDef.h"
#include "IVisitor.h"

ClassDef::ClassDef(const NameTokPtr& name, const ExprTypeList& bases, const StmtTypeList& body, const DecoratorsTypeList& decs, const KeywordTypeList& keywords, const exprTypePtr& starargs, const exprTypePtr& kwargs, int nodeId):
    stmtType(nodeId),
    _name(name),
    _bases(bases),
    _body(body),
    _decs(decs),
    _keywords(keywords),
    _starargs(starargs),
    _kwargs(kwargs)
{
}
    
ClassDef::~ClassDef()
{
    _bases.clear();_body.clear();_decs.clear();_keywords.clear();
}
    
Ast::AstTypes ClassDef::type() const
{
    return Ast::ClassDef;
}
    

NameTokPtr ClassDef::name()
{
    return _name;
}

void ClassDef::setName(const NameTokPtr& name)
{
    _name = name;
}

ExprTypeList ClassDef::bases()
{
    return _bases;
}

void ClassDef::setBases(const ExprTypeList& bases)
{
    _bases = bases;
}

StmtTypeList ClassDef::body()
{
    return _body;
}

void ClassDef::setBody(const StmtTypeList& body)
{
    _body = body;
}

DecoratorsTypeList ClassDef::decs()
{
    return _decs;
}

void ClassDef::setDecs(const DecoratorsTypeList& decs)
{
    _decs = decs;
}

KeywordTypeList ClassDef::keywords()
{
    return _keywords;
}

void ClassDef::setKeywords(const KeywordTypeList& keywords)
{
    _keywords = keywords;
}

exprTypePtr ClassDef::starargs()
{
    return _starargs;
}

void ClassDef::setStarargs(const exprTypePtr& starargs)
{
    _starargs = starargs;
}

exprTypePtr ClassDef::kwargs()
{
    return _kwargs;
}

void ClassDef::setKwargs(const exprTypePtr& kwargs)
{
    _kwargs = kwargs;
}

    
QString ClassDef::toString() const
{
    return QString("ClassDef[name=%1, bases=%2, body=%3, decs=%4, keywords=%5, starargs=%6, kwargs=%7]").
                arg(_name ? _name->toString():"").
                arg(_bases.toString()).
                arg(_body.toString()).
                arg(_decs.toString()).
                arg(_keywords.toString()).
                arg(_starargs ? _starargs->toString():"").
                arg(_kwargs ? _kwargs->toString():"");
}
    
void ClassDef::accept(IVisitor* visitor, const SimpleNodePtr& node)
{
    visitor->visitClassDef(node.dynamicCast<ClassDef>());
}
    
void ClassDef::traverse(IVisitor* visitor)
{
    if (_name != NULL)
        _name->accept(visitor, _name);
    _bases.traverse(visitor);
    _body.traverse(visitor);
    _decs.traverse(visitor);
    _keywords.traverse(visitor);
    if (_starargs != NULL)
        _starargs->accept(visitor, _starargs);
    if (_kwargs != NULL)
        _kwargs->accept(visitor, _kwargs);
}